
call setenv 2>NUL

if ""%1""=="""" goto doneSetArgs
set CATALINA_HOME=%1
shift
if ""%1""=="""" goto doneSetArgs
set WAR_APP=%1
shift
if ""%1""=="""" goto doneSetArgs
set WAR_FILE=%1
:doneSetArgs

if exist "%CATALINA_HOME%\bin\catalina.bat" goto ok1
echo The CATALINA_HOME environment variable is not defined correctly
pause
goto end

:ok1
if not ""%WAR_APP%""=="""" goto ok2
echo The WAR_APP environment variable is not defined
pause
goto end

:ok2
if exist "%WAR_FILE%" goto ok3
echo The WAR_FILE environment variable is not defined or the file does not exists
pause
goto end

:ok3
call tomcatclean.cmd

:repeat
setlocal
copy %WAR_FILE% %CATALINA_HOME%\webapps
set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"
echo %EXECUTABLE%
cd /d "%CATALINA_HOME%\bin"
call "%EXECUTABLE%" run
@echo on

endlocal
call tomcatclean.cmd
pause
goto repeat

:end